package com.jiang;

import com.jiang.util.JdbcUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class UserController {
    public UserController(){
        System.out.println ("自动加载UserController" );
    }

    public String test(){
        return "test";
    }

    public String userlogin(String zhanghao,String mima){
        try {
            Connection conn = JdbcUtil.getConn ( );
            PreparedStatement ps = JdbcUtil.getPs ("select * from hao where zhanghao=?");
            ps.setString (1,zhanghao);
            ResultSet rs = ps.executeQuery ( );
            if (!rs.next ()){
                return "用户不存在";
            }
            User user = new User (rs.getString ("id"),rs.getString ("zhanghao"),rs.getString ("mima"));
            if (!user.getMima ().equals (mima)){
                return "密码错误";
            }

        }catch(Exception e){
            e.printStackTrace ();
        }
        return "？？？？";
    }
}
